<template>
  <div class="mod-config" style="margin-left: 15px;margin-top: 16px;">

    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.keyword" placeholder="用户账号" clearable />
      </el-form-item>

      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="listLoading" :data="dataList" border style="width: 99%;">
      <el-table-column prop="id" header-align="center" align="center" label="序号" />

      <el-table-column prop="username" header-align="center" align="center" label="用户账号" />

      <el-table-column prop="ipaddr" header-align="center" align="center" label="登录IP地址" />

      <el-table-column prop="status" header-align="center" align="center" label="登录状态">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status === 0" size="small" type="success">成功</el-tag>
          <el-tag v-else-if="scope.row.status === 1" size="small" type="danger">失败</el-tag>
        </template>
      </el-table-column>

      <el-table-column prop="msg" header-align="center" align="center" label="提示信息" />

      <el-table-column prop="accessTime" header-align="center" align="center" label="访问时间" />
    </el-table>

    <!-- 分页 -->
    <el-pagination
      :current-page="currentPage"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalCount"
      style="padding: 30px 0; text-align: center;"
      layout="total, sizes, prev, pager, next, jumper"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
import api from '@/api/system/logs'
export default {
  data() {
    return {
      dataForm: {
        keyword: ''
      },
      // 数据列表
      dataList: [],
      // 当前页码
      currentPage: 1,
      // 每页记录数
      pageSize: 10,
      // 总页数
      totalPage: 0,
      // 总记录数
      totalCount: 0,
      // 是否显示"等待数据显示"动画
      listLoading: false
    }
  },
  // 页面渲染前调用
  created() {
    this.getDataList()
  },
  methods: {
    getDataList() {
      api.getLoginLogList({
        'page': this.currentPage,
        'limit': this.pageSize,
        'keyword': this.dataForm.keyword
      }).then(res => {
        this.listLoading = true

        this.currentPage = res.data.currPage
        this.pageSize = res.data.pageSize
        this.totalCount = res.data.totalCount
        this.totalPage = res.data.totalPage
        this.dataList = res.data.records

        this.listLoading = false
      })
    },
    // 每页数
    handleSizeChange(val) {
      this.pageSize = val
      this.currentPage = 1
      this.getDataList()
    },
    // 当前页
    handleCurrentChange(val) {
      this.currentPage = val
      this.getDataList()
    }
  }
}
</script>
<style>

</style>
